﻿/* 
 Copyright (C) 2011  Amblox Project

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Data;

using Amblox.Database;
using Amblox.Managers;

namespace Amblox.Game
{
    public class Habbo
    {
        public int ID;
        public string Name;
        public string RealName;
        public string Motto;
        public int Rank;
        public string Look;
        public char Gender;

        public int Respects;
        public int RemainingRespects;

        public int Credits;
        public int Pixels;

        public Fuselist Fuselist;

        public HabboClient Client;

        public Habbo(int id)
        {
            ID = id;

            DataRow dRow;

            using (DatabaseClient dbClient = Environment.dbManager.GetClient())
            {
                dRow = dbClient.ReadDataRow("SELECT id, name, motto, rank, look, gender, credits, pixels FROM users WHERE id = " + ID);

                Respects = dbClient.ReadInt("SELECT COUNT(id) FROM user_respects WHERE user = " + ID);
                RemainingRespects = Convert.ToInt32(Environment.Config["Game.DailyRespects"]) - dbClient.ReadInt("SELECT COUNT(id) FROM user_respects WHERE date = '" + DateTime.Now.ToShortDateString() + "' AND giver = " + ID);
            }

            if (RemainingRespects < 0)
                RemainingRespects = 0;

            Name = (string)dRow["name"];
            RealName = "";
            Motto = (string)dRow["motto"];
            Rank = Convert.ToInt32((string)dRow["rank"]);
            Look = (string)dRow["look"];
            Gender = Convert.ToChar((string)dRow["gender"]);

            Credits = (int)dRow["credits"];
            Pixels = (int)dRow["pixels"];

            Fuselist = new Fuselist(this);

            HabboManager.AddHabbo(this);
        }

        public void SetClient(HabboClient Client)
        {
            this.Client = Client;
        }

        public void OnClientDestroyed()
        {
            if (this.Client.Messenger != null)
                this.Client.Messenger.MyStatusChange();
            this.Client.Habbo = null;
            this.Client = null;
        }
    }
}
